package com.xls.future.activity;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.WindowManager;
import android.widget.ImageView;

import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
import com.xls.future.R;
import com.xls.future.utils.GlideApp;
import com.xls.future.utils.ScreenUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static android.os.Build.VERSION.SDK;
import static android.os.Build.VERSION.SDK_INT;

/**
 * Created by Administrator on 2017/9/1 0001.
 */

public class ImageActivity extends AppCompatActivity {

    @BindView(R.id.iv_source_image)
    ImageView ivSourceImage;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_image);
        ButterKnife.bind(this);
        Log.d("xls","ImageActivity create");
        supportPostponeEnterTransition();
        String url = getIntent().getStringExtra("url");
        GlideApp.with(this)
                .load(url)
                .skipMemoryCache(true)
                .transition(DrawableTransitionOptions.withCrossFade())
                .override(ScreenUtil.getScreenWidth(this),ScreenUtil.getScreenHeight(this))
                .into(new SimpleTarget<Drawable>() {
                    @Override
                    public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
                        ivSourceImage.setImageDrawable(resource);
                        supportStartPostponedEnterTransition();
                    }
                });

    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        Log.d("xls","ImageActivity onNewIntent");
    }

    @OnClick(R.id.iv_source_image)
    public void onViewClicked() {
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        if(Build.VERSION.SDK_INT>=21){
            this.finishAfterTransition();
        }else{
            finish();
        }

    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
}
